home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ELECTRON / PCB_DESI / 1540.ZIP / PCBCA110.ZIP / PCBROUTE.C < prev    next >
C/C++ Source or Header  |  1992-08-27  |  5KB  |  123 lines

  1. /*
  2. ** printed circuit board autorouter, Copyright (C) Randy Nevin 1989, 1990.
  3. **
  4. ** you may give this software to anyone, make as many copies as you like, and
  5. ** post it on public computer bulletin boards and file servers. you may not
  6. ** sell it or charge any fee for distribution (except for media and postage),
  7. ** remove this comment or the copyright notice from the code, or claim that
  8. ** you wrote this code or anything derived from it. you may modify the code as
  9. ** much as you want (please document clearly with comments, and maintain the
  10. ** coding style), but programs which are derived from this one are subject to
  11. ** the conditions stated here. i am providing this code so that people can
  12. ** learn from it, so if you distribute it, please include source code, not
  13. ** just executables. contact me to report bugs or suggest enhancements; i do
  14. ** not guarantee support, but i will make an effort to help you, and i want to
  15. ** act as a central clearing house for future versions. you should contact me
  16. ** before undertaking a significant development effort, to avoid reinventing
  17. ** the wheel. if you come up with an enhancement you consider particularly
  18. ** useful, i would appreciate being informed so that it can be incorporated in
  19. ** future versions. my address is: Randy Nevin, 24135 SE 16th PL, Issaquah,
  20. ** WA 98027, USA. this code is available directly from the author; just send a
  21. ** 360k floppy and a self-addressed floppy mailer with sufficient postage.
  22. **
  23. ** HISTORY
  24. ** (name        date        description)
  25. ** ----------------------------------------------------
  26. ** randy nevin        2/1/89        initial version
  27. ** randy nevin        2/4/89        made retrace table driven, instead of
  28. **                    doubly-nested switch statements.
  29. ** randy nevin        2/4/89        changed dir from int to char (cut
  30. **                    storage for it in half).
  31. ** randy nevin        2/8/89        changed SetQueue and ReSetQueue to
  32. **                    give priority to goal nodes.
  33. ** randy nevin        2/11/89        don't output incremental search
  34. **                    results if stdout is redirected.
  35. ** randy nevin        2/11/89        released version 1.00
  36. ** randy nevin        5/7/89        added /N switch (don't sort
  37. **                    non-PRIORITY CONNECTs)
  38. ** randy nevin        12/27/89    removed code for compensating from
  39. **                    edge of hole to center of hole; just
  40. **                    approximate distance between centers
  41. **                    of two holes (simplify)
  42. ** randy nevin        12/29/89    added code to keep traces from
  43. **                    touching corner of a hole/via cell,
  44. **                    and to keep from drilling a via where
  45. **                    a corner of its cell touches a trace
  46. ** randy nevin        12/29/89    released version 1.10
  47. */
  48.  
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51.  
  52. #ifndef VMS
  53. #include <io.h>
  54. #endif
  55.  
  56. #include <time.h>
  57. #include <string.h>
  58. #include "cell.h"
  59.  
  60. /*
  61. ** if you run out of memory while routing large boards, there are two things
  62. ** you can do: (1) go into your config.sys file and disable everything you
  63. ** don't need. getting rid of things like ansi.sys, ramdisks, disk caches, and
  64. ** other terminate and stay resident (tsr) programs can free a lot of memory.
  65. ** (2) link the router, inspect the .map file, relink with the /CPARMAXALLOC:n
  66. ** switch, where n is calculated to allow for a near heap of about 5k. read
  67. ** the linker documentation before you do this. for me, the route.map file
  68. ** says the program needs 81EFh bytes. to this i add 1400h (5k) for a near
  69. ** heap to get 95EFh bytes or 95Fh paragraphs, which is 2399 decimal.
  70. */
  71.  
  72. int JustBoard = 0; /* need all data structures, not just the board */
  73. int SortConnects = 1; /* default is to sort non-PRIORITY CONNECTs */
  74. int Ntotal; /* total number of CONNECTs to make */
  75.  
  76. extern int Initialize( char *, int );
  77. extern void Solve( void );
  78. extern void Report( FILE * );
  79.  
  80. void main( int, char *[] );
  81.  
  82. void main ( argc, argv ) /* input board, route traces, output routed board */
  83.     int argc;
  84.     char *argv[];
  85.     {
  86.     char *self, *p;
  87.     FILE *fp;
  88.     long start, stop;
  89.  
  90.     printf( "Copyright (C) Randy Nevin, 1989, 1990. Version 1.10\n" );
  91.     printf( "See source code for rights granted.\n\n" );
  92.     start = time( NULL );
  93.     self = argv[0];
  94.     /* get rid of initial part of path */
  95.     if ((p = strrchr( self, '\\' )) || (p = strrchr( self, ':' )))
  96.         self = ++p;
  97.     /* get rid of extension */
  98.     if ((p = strrchr( self, '.' )) && !stricmp( p, ".EXE" ))
  99.         *p = 0;
  100.     if (argc == 4 && !stricmp( argv[1], "/n" )) {
  101.         SortConnects = 0; /* don't do sorting */
  102.         argv[1] = argv[2];
  103.         argv[2] = argv[3];
  104.         argc = 3;
  105.         }
  106.     else if (argc != 3) { /* need infile and outfile */
  107.         fprintf( stderr, "usage: %s [/N] infile outfile\n", self );
  108.         fprintf( stderr,
  109.             " N = no sorting of non-PRIORITY CONNECTs\n" );
  110.         exit( -1 );
  111.         }
  112.     if (!(fp = fopen( argv[2], "wb" ))) {
  113.         fprintf( stderr, "can't open %s\n", argv[2] );
  114.         exit( -1 );
  115.         }
  116.     Ntotal = Initialize( argv[1], 1 ); /* echo memory used */
  117.     Solve();
  118.     Report( fp );
  119.     stop = time( NULL ) - start;
  120.     printf( "time = %ld second%s\n", stop, (stop == 1) ? "" : "s" );
  121.     exit( 0 );
  122.     }
  123.